package com.saic.localfileloader.table;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

public abstract class TableLoader {

	String localpath = null;// 本地文件存放文件夹
	String tablename = null;// ORACLE数据库对应表
	String sql = null;// 产生SQL插入语句
	String token = null;// 定义分隔符
	String charsetName = null;// 文件字符集
	boolean isdelete = false;// 是否需要删除文件

	public String getCharset() {
		return this.charsetName;
	}

	public TableLoader(String localpath, String tablename, String token) {
		this.localpath = localpath;
		this.tablename = tablename;
		this.token = token;
	}

	public String getLocalPath() {
		return this.localpath;
	}

	public String getTableName() {
		return this.tablename;
	}

	public static void print(String msg) {
		try {
			BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
					new FileOutputStream("log.txt", true)));
			bw.write(msg + "\n");
			bw.flush();
			bw.close();
		} catch (IOException e) {
			System.out.println("Log: failed! <" + msg + ">");
		}
	}

	public static String validate(String input) {

		if (input.contains("\""))
			input = input.replaceAll("\\\"", "");

		if (input.endsWith("-"))
			input = "-" + input.substring(0, input.length() - 1);

		if (input.contains(","))
			input = input.replaceAll("\\,", "");

		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < input.length(); i++)
			if (input.charAt(i) >= ' ')
				sb.append(input.charAt(i));

		return sb.toString();
	}

	public abstract String getHeader();

	public abstract String getInsertSQL(String line);
	
	public abstract String getDeleteSQL();

}